<template>
  <el-row :gutter="10" class="mb8">
<!--    <el-col :span="1.5">-->
<!--      <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="Plus"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['scm:scmInquiriesOut:add']"-->
<!--      >新增</el-button>-->
<!--    </el-col>-->
    <el-col :span="1.5">
      <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['scm:scmInquiriesOut:edit']"
      >修改</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['scm:scmInquiriesOut:remove']"
      >删除</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleGenerate"
          v-hasPermi="['scm:scmInquiriesOut:generate']"
      >生成询价单</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
          type="primary"
          plain
          icon="Right"
          @click="handleToSupplierQuotes"
          v-hasPermi="['scm:ScmInquiriesIn:export']"
      >确认询价</el-button>
    </el-col>
    <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :search="false" :columns="columns" showColumnsType="transfer"
                   :linked-id="projectId" :attachment-type="2" :attachment-path="projectCode"
    ></right-toolbar>
  </el-row>

  <el-table v-loading="loading" :data="scmInquiriesOutList" @selection-change="handleSelectionChange" :scrollbar-always-on="true" :row-class-name="tableRowClassName" >
    <el-table-column type="selection" width="55" align="center" />
    <el-table-column label="图号" align="center" prop="scmProjectProducts.drawingNumber" fixed width="98"/>
    <el-table-column label="版本" align="center" prop="scmProjectProducts.version" fixed v-if="columns[0].visible" />
    <el-table-column label="内版本" align="center" prop="scmProjectProducts.internalVersion" fixed v-if="columns[1].visible" />
    <el-table-column label="品名" align="center" prop="scmProjectProducts.productName" fixed v-if="columns[2].visible" />
<!--    <el-table-column label="${comment}" align="center" prop="id" />-->
<!--    <el-table-column label="询价单编号" align="center" prop="code" />-->
<!--    <el-table-column label="项目ID" align="center" prop="projectId" />-->
<!--    <el-table-column label="产品ID" align="center" prop="productId" />-->
<!--    <el-table-column label="供应商ID" align="center" prop="supplierId" />-->
    <el-table-column label="供应商名" align="center" prop="supplierName" v-if="columns[3].visible" />
    <el-table-column label="供应商区分" align="center" prop="type" v-if="columns[4].visible" >
      <template #default="scope">
        <dict-tag :options="scm_inquiries_type" :value="scope.row.type"/>
      </template>
    </el-table-column>
    <el-table-column label="材质" align="center" prop="scmProjectProducts.material" v-if="columns[5].visible" />
    <el-table-column label="规格型号" align="center" prop="scmProjectProducts.specification" v-if="columns[6].visible" />
    <el-table-column label="颜色" align="center" prop="scmProjectProducts.color" v-if="columns[7].visible" />
    <el-table-column label="单台 用量" align="center" v-if="columns[8].visible" >
      <el-table-column label="数量" align="center" prop="onceQuantity" />
      <el-table-column label="单位" align="center" prop="onceUnit" />
    </el-table-column>
    <el-table-column label="月度 用量" align="center" v-if="columns[9].visible" >
      <el-table-column label="数量" align="center" prop="monthlyQuantity" />
      <el-table-column label="单位" align="center" prop="monthlyUnit" />
    </el-table-column>
    <el-table-column label="年度 用量" align="center" v-if="columns[10].visible" >
      <el-table-column label="数量" align="center" prop="yearlyQuantity" />
      <el-table-column label="单位" align="center" prop="yearlyUnit" />
    </el-table-column>
    <el-table-column label="一次性" align="center" v-if="columns[11].visible" >
      <el-table-column label="数量" align="center" prop="disposableQuantity" />
      <el-table-column label="单位" align="center" prop="disposableUnit" />
      <el-table-column label="目标单价" align="center" prop="disposableUnitPrice" />
      <el-table-column label="希望纳期" align="center" prop="disposableExpectedDeliveryDate" width="110" />
    </el-table-column>
    <el-table-column label="一次性试做" align="center" v-if="columns[12].visible" >
      <el-table-column label="数量" align="center" prop="disposableTryQuantity" />
      <el-table-column label="单位" align="center" prop="disposableTryUnit" />
      <el-table-column label="目标单价" align="center" prop="disposableTryUnitPrice" />
      <el-table-column label="希望纳期" align="center" prop="disposableTryExpectedDeliveryDate" width="110" />
    </el-table-column>
    <el-table-column label="试做" align="center" v-if="columns[13].visible" >
      <el-table-column label="数量" align="center" prop="tryQuantity" />
      <el-table-column label="单位" align="center" prop="tryUnit" />
      <el-table-column label="目标单价" align="center" prop="tryUnitPrice"/>
      <el-table-column label="希望纳期" align="center" prop="tryExpectedDeliveryDate" width="110"/>
    </el-table-column>
    <el-table-column label="量产" align="center" v-if="columns[14].visible" >
      <el-table-column label="数量" align="center" prop="massQuantity" />
      <el-table-column label="单位" align="center" prop="massUnit" />
      <el-table-column label="目标单价" align="center" prop="massUnitPrice" />
      <el-table-column label="希望纳期" align="center" prop="massExpectedDeliveryDate" width="110"/>
    </el-table-column>
    <el-table-column label="希望报价日" align="center" prop="expectedQuotationDate" width="110" v-if="columns[15].visible" >
      <template #default="scope">
        <span>{{ parseTime(scope.row.expectedQuotationDate, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
    <el-table-column label="希望到货日" align="center" prop="expectedDeliveryDate" width="110" v-if="columns[16].visible" >
      <template #default="scope">
        <span>{{ parseTime(scope.row.expectedDeliveryDate, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
    <el-table-column label="需求资料" align="left" prop="expectedDatum" :show-overflow-tooltip="true" width="130" v-if="columns[17].visible" />
    <el-table-column label="备注" align="left" prop="remarks" :show-overflow-tooltip="true" width="100" v-if="columns[18].visible"  />
    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="130" >
      <template #default="scope">
        <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['scm:scmInquiriesOut:edit']">修改</el-button>
        <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['scm:scmInquiriesOut:remove']">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

  <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
  />

  <!-- 添加或修改供应商询价单对话框 -->
  <el-dialog :title="title" v-model="open" width="1300px" append-to-body>
    <el-form ref="scmInquiriesOutRef" :model="form" :rules="rules" label-width="120px">
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="图号" prop="scmProjectProducts.drawingNumber">
            <el-input v-model="form.scmProjectProducts.drawingNumber" placeholder="请输入图号" readonly disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="品名" prop="scmProjectProducts.productName">
            <el-input v-model="form.scmProjectProducts.productName" placeholder="请输入品名" readonly disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="版本" prop="scmProjectProducts.version">
            <el-input v-model="form.scmProjectProducts.version" placeholder="请输入版本" readonly disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="内版本" prop="scmProjectProducts.internalVersion">
            <el-input v-model="form.scmProjectProducts.internalVersion" placeholder="请输入内版本" readonly disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="供应商名" prop="supplierName">
            <el-input v-model="form.supplierName" placeholder="请输入供应商名称" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="供应商区分" prop="type">
            <el-select v-model="form.type" placeholder="请选择询价单类型">
              <el-option
                  v-for="dict in scm_inquiries_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6"></el-col>
        <el-col :span="6">
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="材质" prop="scmProjectProducts.material">
            <el-input v-model="form.scmProjectProducts.material" placeholder="请输入材质" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="规格型号" prop="scmProjectProducts.specification">
            <el-input v-model="form.scmProjectProducts.specification" placeholder="请输入规格型号" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="颜色" prop="scmProjectProducts.color">
            <el-input v-model="form.scmProjectProducts.color" placeholder="请输入颜色" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="(单台用量)数量" prop="onceQuantity">
            <el-input-number v-model="form.onceQuantity" placeholder="请输入单台数量" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(单台用量)单位" prop="onceUnit">
            <el-input v-model="form.onceUnit" placeholder="请输入单台单位" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(月用量)数量" prop="monthlyQuantity">
            <el-input-number v-model="form.monthlyQuantity" placeholder="请输入月数量" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(月用量)单位" prop="monthlyUnit">
            <el-input v-model="form.monthlyUnit" placeholder="请输入月单位" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="(年用量)数量" prop="yearlyQuantity">
            <el-input-number v-model="form.yearlyQuantity" placeholder="请输入年数量" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(年用量)单位" prop="yearlyUnit">
            <el-input v-model="form.yearlyUnit" placeholder="请输入年单位" />
          </el-form-item>
        </el-col>
        <el-col :span="6"></el-col>
        <el-col :span="6">
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="(一次性)数量" prop="disposableQuantity">
            <el-input-number v-model="form.disposableQuantity" placeholder="请输入一次性数量" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(一次性)单位" prop="disposableUnit">
            <el-input v-model="form.disposableUnit" placeholder="请输入一次性单位" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(一次性)目标单价" prop="disposableUnitPrice" label-width="160">
            <el-input-number v-model="form.disposableUnitPrice" placeholder="请输入一次性目标单价" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" :precision="2" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(一次性)希望纳期" prop="disposableExpectedDeliveryDate" label-width="160">
            <el-date-picker clearable v-model="form.disposableExpectedDeliveryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择一次性希望纳期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="(一次性试做)数量" prop="disposableTryQuantity">
            <el-input-number v-model="form.disposableTryQuantity" placeholder="请输入一次性试做数量" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(一次性试做)单位" prop="disposableTryUnit">
            <el-input v-model="form.disposableTryUnit" placeholder="请输入一次性试做单位" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(一次性试做)目标单价" prop="disposableTryUnitPrice" label-width="160">
            <el-input-number v-model="form.disposableTryUnitPrice" placeholder="请输入一次性试做目标单价" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" :precision="2" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(一次性试做)希望纳期" prop="disposableTryExpectedDeliveryDate" label-width="160">
            <el-date-picker clearable v-model="form.disposableTryExpectedDeliveryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择一次性试做希望纳期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="(试做)数量" prop="tryQuantity">
            <el-input-number v-model="form.tryQuantity" placeholder="请输入试做数量" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(试做)单位" prop="tryUnit">
            <el-input v-model="form.tryUnit" placeholder="请输入试做单位" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(试做)目标单价" prop="tryUnitPrice" label-width="160">
            <el-input-number v-model="form.tryUnitPrice" placeholder="请输入试做目标单价"  type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" :precision="2" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(试做)希望纳期" prop="tryExpectedDeliveryDate" label-width="160">
            <el-date-picker clearable v-model="form.tryExpectedDeliveryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择试做希望纳期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="(量产)数量" prop="massQuantity">
            <el-input-number v-model="form.massQuantity" placeholder="请输入量产数量" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(量产)单位" prop="massUnit">
            <el-input v-model="form.massUnit" placeholder="请输入量产单位" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(量产)目标单价" prop="massUnitPrice" label-width="160">
            <el-input-number v-model="form.massUnitPrice" placeholder="请输入量产目标单价" type="number" :min="0" :controls="false" class="number-right" style="width: 100%;" :precision="2" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="(量产)希望纳期" prop="massExpectedDeliveryDate" label-width="160">
            <el-date-picker clearable v-model="form.massExpectedDeliveryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择量产希望纳期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="希望报价日" prop="expectedQuotationDate">
            <el-date-picker clearable v-model="form.expectedQuotationDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择希望报价日">
            </el-date-picker>
          </el-form-item>

        </el-col>
        <el-col :span="6">
          <el-form-item label="希望到货日" prop="expectedDeliveryDate">
            <el-date-picker clearable v-model="form.expectedDeliveryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择希望到货日">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="需求资料" prop="expectedDatum">
            <el-input v-model="form.expectedDatum" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="备注" prop="remarks">
            <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-row>

<!--      <el-form-item label="询价单号" prop="code">-->
<!--        <el-input v-model="form.code" placeholder="请输入询价单编号" />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="项目ID" prop="projectId">-->
<!--        <el-input v-model="form.projectId" placeholder="请输入项目ID" />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="产品ID" prop="productId">-->
<!--        <el-input v-model="form.productId" placeholder="请输入产品ID" />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="供应商ID" prop="supplierId">-->
<!--        <el-input v-model="form.supplierId" placeholder="请输入供应商ID" />-->
<!--      </el-form-item>-->



    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </template>
  </el-dialog>

</template>

<script setup>
import {
  listScmInquiriesOut,
  getScmInquiriesOut,
  delScmInquiriesOut,
  addScmInquiriesOut,
  updateScmInquiriesOut,
  createScmInquiriesOut
} from "@/api/scm/scmInquiriesOut";
import {createScmSupplierQuotes} from "@/api/scm/scmSupplierQuotes.js";

const props = defineProps({
  projectId: {
    type: String,
    default: ''
  },
  projectCode: {
    type: String,
    default: ''
  }
})

const { proxy } = getCurrentInstance();
const { scm_inquiries_type } = proxy.useDict('scm_inquiries_type');

const scmInquiriesOutList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    code: null,
    projectId: props.projectId,
    productId: null,
    supplierId: null,
    supplierName: null,
  },
  rules: {
    projectId: [
      { required: true, message: "项目ID不能为空", trigger: "blur" }
    ],
    productId: [
      { required: true, message: "产品ID不能为空", trigger: "blur" }
    ],
    supplierName: [
      { required: true, message: "供应商名称不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

// const localProjectId = ref(props.projectId);
// 监听 projectId 变化
watch(
    () => props.projectId,
    (newVal) => {
      console.log('projectId changed to:', newVal);
      queryParams.value.projectId = newVal; // 更新本地变量
      getList();
    }
);

/** 查询供应商询价单列表 */
function getList() {
  loading.value = true;
  drawingNumberColorMap.clear();
  colorCounter = 0;
  listScmInquiriesOut(queryParams.value).then(response => {
    scmInquiriesOutList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    code: null,
    projectId: null,
    productId: null,
    supplierId: null,
    supplierName: null,
    type: null,
    material: null,
    specification: null,
    color: null,
    onceQuantity: null,
    onceUnit: null,
    monthlyQuantity: null,
    monthlyUnit: null,
    yearlyQuantity: null,
    yearlyUnit: null,
    disposableQuantity: null,
    disposableUnit: null,
    disposableUnitPrice: 0 ,
    disposableExpectedDeliveryDate: null,
    disposableTryQuantity: null,
    disposableTryUnit: null,
    disposableTryUnitPrice: 0,
    disposableTryExpectedDeliveryDate: null,
    tryQuantity: null,
    tryUnit: null,
    tryUnitPrice: 0,
    tryExpectedDeliveryDate: null,
    massQuantity: null,
    massUnit: null,
    massUnitPrice: 0,
    massExpectedDeliveryDate: null,
    expectedQuotationDate: null,
    expectedDeliveryDate: null,
    expectedDatum: null,
    remarks: null,
    scmProjectProducts: {
      drawingNumber: null,
      version: null,
      internalVersion: null,
      productName: null,
      material: null,
      inflamingRetardingLevel: null,
      specification: null,
      model: null,
      color: null,
      drawingComposition: null,
    },
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("scmInquiriesOutRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加供应商询价单";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getScmInquiriesOut(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改供应商询价单";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["scmInquiriesOutRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateScmInquiriesOut(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addScmInquiriesOut(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除供应商询价单编号为"' + _ids + '"的数据项？').then(function() {
    return delScmInquiriesOut(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('scm/scmInquiriesOut/export', {
    ...queryParams.value
  }, `scmInquiriesOut_${new Date().getTime()}.xlsx`)
}

/** 生成按钮操作 */
function handleGenerate() {
  proxy.download('scm/scmInquiriesOut/generate', {
    ...queryParams.value
  }, `scmInquiriesOut_${new Date().getTime()}.xlsx`)
}

// 点击“确认询价”按钮触发
const handleToSupplierQuotes = () => {
  createScmSupplierQuotes(queryParams.value.projectId).then(response => {
    proxy.$modal.msgSuccess("添加成功");
  });
}

// 添加颜色映射和计数器
const drawingNumberColorMap = new Map();
let colorCounter = 0;
const colorClasses = ['drawing-number-row-0', 'drawing-number-row-1'];

// 修改 tableRowClassName 函数
function tableRowClassName({ row, rowIndex }) {
  if (!row.scmProjectProducts || !row.scmProjectProducts.drawingNumber) return '';

  // 检查是否已经为该 drawingNumber 分配了颜色
  if (drawingNumberColorMap.has(row.scmProjectProducts.drawingNumber)) {
    return drawingNumberColorMap.get(row.scmProjectProducts.drawingNumber);
  }

  // 为新的 drawingNumber 分配颜色
  const colorClass = colorClasses[colorCounter % colorClasses.length];
  drawingNumberColorMap.set(row.scmProjectProducts.drawingNumber, colorClass);
  colorCounter++;

  return colorClass;
}

// 列显隐信息
const columns = ref([
  { key: 0, label: `版本`, visible: true },
  { key: 1, label: `内版本`, visible: true },
  { key: 2, label: `品名`, visible: true },
  { key: 3, label: `供应商名`, visible: true },
  { key: 4, label: `供应商区分`, visible: true },
  { key: 5, label: `材质`, visible: true },
  { key: 6, label: `规格`, visible: true },
  { key: 7, label: `颜色`, visible: true },
  { key: 8, label: `单台 用量`, visible: true },
  { key: 9, label: `月度 用量`, visible: true },
  { key: 10, label: `年度 用量`, visible: true },
  { key: 11, label: `一次性`, visible: true },
  { key: 12, label: `一次性试做`, visible: true },
  { key: 13, label: `试做`, visible: true },
  { key: 14, label: `量产`, visible: true },
  { key: 15, label: `希望报价日`, visible: true },
  { key: 16, label: `希望到货日`, visible: true },
  { key: 17, label: `需求资料`, visible: true },
  { key: 18, label: `备注`, visible: true }
]);

getList();
</script>

<style >/* 定义10种不同的背景色 */
.el-table .drawing-number-row-0 {
  background: #e8f5e8;
}

.el-table .drawing-number-row-1 {
  background: #e8e8f5;
}

.el-table .drawing-number-row-2 {
  background: #fff0f0;
}
</style>